function initialize(){
		getLocation();
		labelSelect("#htp");
		getMed();
}

function clearBox(x,valor){
		ant = x.value;
		if (x.value == valor){
	    x.value='';
	    x.style.color='black';
		}
}

function validateClear(x,valor){
	if(x.value == ''){
		x.value=valor;
		x.style.color='#BFBABA';
	}
}

var act1=true;
var act2=false;
var act3=false;

function pedidoHandler() {
	act1=true;
	act2=false;
	act3=false;
/*		TODO document.getElementById("tutorialLayer").style.visibility='hidden';
		document.getElementById("promotions").style.visibility='hidden';*/
	if(winW > 1200){
		document.getElementById("htp").setAttribute("style", "height:77px; z-index:25; margin-top:0px");
		document.getElementById("cf").setAttribute("style", "height:70px; z-index:24; margin-top:7px");
		document.getElementById("promo").setAttribute("style", "height:70px; z-index:23; margin-top:7px");
	}
	if(winW < 1200  && winW >= 768){
		document.getElementById("htp").setAttribute("style", "height:55px; z-index:25; margin-top:0px");
		document.getElementById("cf").setAttribute("style", "height:50px; z-index:24; margin-top:5px");
		document.getElementById("promo").setAttribute("style", "height:50px; z-index:23; margin-top:5px");
	}
	if(winW < 768  && winW >= 600){
		document.getElementById("htp").setAttribute("style", "height:45px; z-index:25; margin-top:0px");
		document.getElementById("cf").setAttribute("style", "height:40px; z-index:24; margin-top:5px");
		document.getElementById("promo").setAttribute("style", "height:40px; z-index:23; margin-top:5px");
	}
	if(winW < 600){
		document.getElementById("htp").setAttribute("style", "height:40px; z-index:25; margin-top:0px");
		document.getElementById("cf").setAttribute("style", "height:35px; z-index:24; margin-top:5px");
		document.getElementById("promo").setAttribute("style", "height:35px; z-index:23; margin-top:5px");
	}
}
function howToHandler() {
	act1=false;
	act2=true;
	act3=false;
		/* TODO document.getElementById("tutorialLayer").style.visibility='visible';
		document.getElementById("promotions").style.visibility='hidden';*/
	if(winW > 1200){
		document.getElementById("htp").setAttribute("style", "height:70px; z-index:24; margin-top:7px");
		document.getElementById("cf").setAttribute("style", "height:77px; z-index:25; margin-top:0px");
		document.getElementById("promo").setAttribute("style", "height:70px; z-index:23; margin-top:7px");
	}
	if(winW < 1200  && winW >= 768){
		document.getElementById("htp").setAttribute("style", "height:50px; z-index:24; margin-top:5px");
		document.getElementById("cf").setAttribute("style", "height:55px; z-index:25; margin-top:0px");
		document.getElementById("promo").setAttribute("style", "height:50px; z-index:23; margin-top:5px");
	}
	if(winW < 768  && winW >= 600){
		document.getElementById("htp").setAttribute("style", "height:40px; z-index:24; margin-top:5px");
		document.getElementById("cf").setAttribute("style", "height:45px; z-index:25; margin-top:0px");
		document.getElementById("promo").setAttribute("style", "height:40px; z-index:23; margin-top:5px");
	}
	if(winW < 600){
		document.getElementById("htp").setAttribute("style", "height:35px; z-index:24; margin-top:5px");
		document.getElementById("cf").setAttribute("style", "height:40px; z-index:25; margin-top:0px");
		document.getElementById("promo").setAttribute("style", "height:35px; z-index:23; margin-top:5px");
	}
}
function promotionHandler() {
	act1=false;
	act2=false;
	act3=true;
/*		TODO document.getElementById("promotions").style.visibility='visible';*/
	if(winW > 1200){
		document.getElementById("htp").setAttribute("style", "height:70px; z-index:23; margin-top:7px");
		document.getElementById("cf").setAttribute("style", "height:70px; z-index:24; margin-top:7px");
		document.getElementById("promo").setAttribute("style", "height:77px; z-index:25; margin-top:0px");
	}
	if(winW < 1200  && winW >= 768){
		document.getElementById("htp").setAttribute("style", "height:50px; z-index:23; margin-top:5px");
		document.getElementById("cf").setAttribute("style", "height:50px; z-index:24; margin-top:5px");
		document.getElementById("promo").setAttribute("style", "height:55px; z-index:25; margin-top:0px");
	}
	if(winW < 768  && winW >= 600){
		document.getElementById("htp").setAttribute("style", "height:40px; z-index:23; margin-top:5px");
		document.getElementById("cf").setAttribute("style", "height:40px; z-index:24; margin-top:5px");
		document.getElementById("promo").setAttribute("style", "height:45px; z-index:25; margin-top:0px");
	}
	if(winW < 600){
		document.getElementById("htp").setAttribute("style", "height:35px; z-index:23; margin-top:5px");
		document.getElementById("cf").setAttribute("style", "height:35px; z-index:24; margin-top:5px");
		document.getElementById("promo").setAttribute("style", "height:40px; z-index:25; margin-top:0px");
	}
}

var winW = 1366, winH = 1024, percCol;
var backTop= false;
var res;
var hiddenTop;

function getMed(){ 
//	TODO ELSE
	if (document.body && document.body.offsetWidth) {
		 winW = document.body.offsetWidth;
		 winH = document.body.offsetHeight;
	}
	if (document.compatMode=='CSS1Compat' &&
		    document.documentElement &&
		    document.documentElement.offsetWidth ) {
		 winW = document.documentElement.offsetWidth;
		 winH = document.documentElement.offsetHeight;
	}
	if (window.innerWidth && window.innerHeight) {
		 winW = window.innerWidth;
		 winH = window.innerHeight;
	}
	if(act1=true){
		pedidoHandler();
	}
	if(act2=true){
		howToHandler();
	}
	if(act3=true){
		promotionHandler();
	}
	if (res>900){
		hiddenTop=false;
	}
	if (hiddenTop==false){
		if (res<=900){
			hide();
			unFix();
			hiddenTop=true;
		}
	}
	if (winW > 1200 && res!=1200){
		document.getElementById('css1').href = '/pediOnline/css/indexStyle_1200.css';
		backTop = true;
		latWidth(1028);
		res=1200;
	}
	if (winW < 1200  && winW >= 900 && res!=900){
		document.getElementById('css1').href = '/pediOnline/css/indexStyle_900.css';
		backTop = false;
		latWidth(900);
		res=900;
	}
	if (winW < 900 && winW >= 768 && res!=768){
		document.getElementById('css1').href = '/pediOnline/css/indexStyle_768.css';
		backTop = false;
		latWidth(768);
		res=768;
	}
	if (winW < 768 && winW >= 600 && res!=600){
		document.getElementById('css1').href = '/pediOnline/css/indexStyle_600.css';
		backTop = false;
		latWidth(600);
		res=600;
	}
	if (winW < 600 && winW >= 480 && res!=480){
		document.getElementById('css1').href = '/pediOnline/css/indexStyle_480.css';
		backTop = false;
		latWidth(480);
		res=480;
	}
	if (winW < 480 && res!=320){
		document.getElementById('css1').href = '/pediOnline/css/indexStyle_320.css';
		backTop = false;
		latWidth(320);
		res=320;
	}
};

//TODO FIX
function latWidth(cent){
	var perc1= winW/100;
	perCol= (((winW-cent)/perc1)/2)-1;
	document.getElementById('leftCol').style.width = perCol + "%";
	document.getElementById('rightCol').style.width = perCol + "%";
}	

var resizeTimer;
$(window).resize(function() {
    clearTimeout(resizeTimer);
    resizeTimer = setTimeout(getMed, 100);
});
	
function labelSelect(id){
	$("#htp").removeClass('active');
	$("#cf").removeClass('active');
	$("#promo").removeClass('active');
	$(id).addClass('active');
}

var done=false;

function testScroll(ev){
	getMed();
	if (backTop==true){
    if(window.pageYOffset>113){
    	fix();
    }
    else{
    	unFix();
    }
}
}

function fix(){
	document.getElementById("tabsNav").setAttribute("class","centralCol fixed");
	document.getElementById("tabsNav").setAttribute("style", "padding-top:0px");
	document.getElementById("contMenu").setAttribute("style","position:fixed; top:77px; z-index:16; left:50%; margin-left: -514px;");
	document.getElementById("imanes").setAttribute("style","padding-top:202px");
	document.getElementById("map").setAttribute("style","padding-top:85px; position:fixed; right: 50%; margin-right: -514px; top:94px");
}

function unFix(){
	document.getElementById("tabsNav").setAttribute("class","centralCol");
	document.getElementById("tabsNav").setAttribute("style", "padding-top:27px");
	document.getElementById("contMenu").setAttribute("style","position:relative; top:0px; left:0px; z-index:16");
	document.getElementById("imanes").setAttribute("style","padding-top:0px");
	document.getElementById("map").setAttribute("style","padding-top:0px; position:absolute; right:0px; top:0px");
}

window.onscroll=testScroll


$(document).ready(function(){

	if (done==false){
		initialize();
		done=true;
		console.log("Pase por el Ready, and done esta en: " + done);
		}
	// hide #back-top first
	$("#back-top").hide();
	$("#back-topR").hide();
	$("#vr1").hide();
	$("#vr2").hide();
	$("#vr3").hide();
	$("#vr4").hide();
	
	
	// fade in #back-top
$(function (){
		$(window).scroll(function () {
			if (backTop==true){
			if ($(this).scrollTop() > 100) {
				$('#back-top').fadeIn();
				$('#back-topR').fadeIn();
				$('#vr1').fadeIn();
				$('#vr2').fadeIn();
				$('#vr3').fadeIn();
				$('#vr4').fadeIn();
			} else {
				$('#back-top').fadeOut();
				$('#back-topR').fadeOut();
				$('#vr1').fadeOut();
				$('#vr2').fadeOut();
				$('#vr3').fadeOut();
				$('#vr4').fadeOut();
			}
			}
		});

		// scroll body to 0px on click
		$('#back-top a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
		$('#back-topR a').click(function () {
			$('body,html').animate({
				scrollTop: 0
			}, 800);
			return false;
		});
	});
});

function hide(){
	$("#back-top").hide();
	$("#back-topR").hide();
	$("#vr1").hide();
	$("#vr2").hide();
	$("#vr3").hide();
	$("#vr4").hide();
}


/* LO HIZO EL PIBE DEL LABURO
function scrollTuto() {
	var cartel = document.getElementById("cartel"),
		docWidth = parseInt(window.innerWidth),
		docHeight = parseInt(window.innerHeight),
		cartelWidth = parseInt(cartel.offsetWidth),
		cartelHeight = parseInt(cartel.offsetHeight),
		top = cartel.style.top,
		margin = parseInt(top.substr(0, top.indexOf("px")));

	cartel.style.left = (docWidth/2 - cartelWidth/2) + "px";
	console.log()
	if (margin < (docHeight - cartelHeight*2))
		top = (margin += 10) + "px";
	else
		top = "0px";
	cartel.style.top = top;
	window.setTimeout(update, 50);
}
*/